﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace tempProject
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int a = 10001; a < 10500; a++)
            {
                try
                {
                    string text = GetFile(a);
                    File.WriteAllText(a + ".txt", text);
                }
                catch (Exception e) { Console.WriteLine("Terrible Exception " + e); }
            }
        }

        static string GetFile(int a)
        {
            string digits = a.ToString();
            string url = @"http://www.gutenberg.org/dirs/" + digits[0] + "/" + digits[1] + "/" + digits[2] + "/" + digits[3] + "/" + a + "/" + a + ".txt";
            Console.WriteLine(url);
            HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
            WebResponse response = request.GetResponse();
            StreamReader r=new StreamReader(response.GetResponseStream());
            return r.ReadToEnd();
        }
    }
}
